home *** CD-ROM | disk | FTP | other *** search
/ Rat Attack (UK) (Digital Press Kit - Summer '99) / Rat Attack (UK) (Digital Press Kit - Summer '99).bin / RAT01.DIR / 00022_Script_Image Switch Cast Members < prev    next >
Text File  |  1999-04-26  |  5KB  |  110 lines

  1. -- Image Switch Members
  2.  
  3. -- Media
  4. -- behavior library version 1.1
  5.  
  6. -- Adding this behavior to a sprite allows it to change its cast member when
  7. -- it receives an event.
  8. -- The sprite checks the parameter passed with the event and if it matches the
  9. -- assigned name of the sprite or the assigned 'groupname' of the sprite
  10. -- it switches.  This way multiple sprites can be effected by a single message.
  11.  
  12. -- autohandles MemberAlt, MemberOne being numbers or labels.
  13.  
  14. -- MemberAlt is a cast member (graphic or pict)
  15. -- MemberOne is also
  16. -- Setting is with 1 ( normal ) or 2 ( toggled ) and is also starting state
  17. -- Name is a symbol which is checked for when the script receives a Switch event
  18. -- GroupName is also a symbol checked for, must be a symbol
  19.  
  20. -- receives Switch name
  21.  
  22. property  Name, Setting, Memberalt, MemberOne, GroupName
  23. property MemberAltName 
  24.  
  25. on SetState me, state, addressee
  26.   if voidP(Addressee) then
  27.     do_SetState me, state
  28.   else    
  29.     case Addressee of
  30.       #all: do_SetState me, state
  31.       (the Name of me): do_SetState me, state
  32.       (the GroupName of me): do_SetState me, state
  33.     end case
  34.   end if
  35. end
  36.  
  37. on SwitchStates me, Addressee 
  38.   if voidP( Addressee ) then
  39.     do_SwitchStates me
  40.   else    
  41.     case Addressee of
  42.       #all: do_SwitchStates me
  43.       (the Name of me): do_SwitchStates me
  44.       (the GroupName of me): do_SwitchStates me
  45.     end case
  46.   end if 
  47. end
  48.  
  49. ---
  50. on do_SetState me, state 
  51.   set the Setting of me = state
  52.   if state = 1 then
  53.     set the member of sprite the spritenum of me to the MemberOne of me
  54.   else
  55.     set the member of sprite the spritenum of me to the MemberAlt of me
  56.   end if
  57. end
  58.  
  59. on do_SwitchStates me
  60.   if ( the Setting of me = 1 ) then
  61.     set the Setting of me = 2
  62.     set the member of sprite the spritenum of me to the MemberAlt of me
  63.   else if ( the Setting of me = 2 ) then
  64.     set the Setting of me = 1
  65.     set the member of sprite the spritenum of me to the MemberOne of me
  66.   end if
  67.   return the Setting of me
  68. end
  69.  
  70. ---
  71.  
  72. on BeginSprite me
  73.   
  74.   set the MemberOne of me = the member of sprite ( the spriteNum of me ) 
  75.   set the MemberAlt of me = member ( the MemberAltName of me ) 
  76.   
  77.   if setting = TRUE then -- initially alternate
  78.     do_SetState me, 2 
  79.   else  -- initally memberOne.
  80.     do_SetState me, 1 
  81.   end if 
  82. end
  83.  
  84. on getPropertyDescriptionList
  85.   if the currentspritenum = 0 then 
  86.     set memdefault = 0 
  87.   else
  88.     set memref = the member of sprite the currentspritenum
  89.     set castlibnum = the castlibnum of memref
  90.     set memdefault = member (the membernum of member memref + 1) of castlib castlibnum
  91.   end if
  92.   
  93.   set p_list = [           #Name: [ #comment:   "Item Name:",                     #format:   #symbol,                    #default:   #twostate1 ],      #MemberAltName: [ #comment:   "Alternate Image Name:",                    #format:   #graphic,                    #default:    memdefault],        #Setting: [ #comment:   "Initially Toggled:",                     #format:   #boolean,                    #default:    FALSE ],      #GroupName: [ #comment:   "Group Name:",                     #format:   #symbol,                    #default:   #group1 ]                  ]
  94.   
  95.   return p_list  
  96.   
  97. end
  98.  
  99. on getBehaviorDescription
  100.   return "Switches cast members when the SwitchStates message is received. Switches to a particular state when the SetState message is received. Enter a Group Name to include the current sprite in a group of sprites that respond to the same message. " & RETURN & "PARAMETERS:" & RETURN & "ò Item Name - (optional) Enter an item name to identify the current sprite so that it can receive a specific message. Do not use spaces. Use the name as an argument for the Message Sprite or Message All Sprites behaviors."  & RETURN & "ò Alternate Image - number of castmember whose image will replace normal image.  Must be stored in same cast library as Normal castmember."  & RETURN & "ò Initially Toggled - Turn this option on if sprite's current cast member represents the alternate rather than the normal state of the sprite."  & RETURN & "ò Group Name - (optional) Enter a Group Name to include the current sprite in a group of sprites that respond to the same message. Do not use spaces. Use the name as an argument for the Message Sprite or Message All Sprites behaviors."  & RETURN & "MESSAGES:" & RETURN & "ò SwitchStates [ID] - Switches the sprite's cast member. ID is the Item Name or Group Name of the sprite. Returns the current state of the sprite, 0 (normal) or 1 (alternate)."& RETURN & "ò SetState {0 or 1}, [ID] - Sets the sprite to state 0 (normal) or 1 (alternate). ID is the Item Name or Group Name of the sprite. If the ID is omitted any sprite receiving the message will SetState."
  101.   
  102. end
  103.  
  104.  
  105.  
  106. on getAssocMembers --added, fmk
  107.   set myPropList = [MemberAltName ]
  108.   
  109.   return myPropList
  110. end getAssocMembers